#include <bits/stdc++.h>
// 2025/02/05
// tag: 
// Author: Zhang Muen
using namespace std;

using int64 = int64_t;

struct node{
    int h, a, c;
} cow[401];

int n, dp[40001];

bool cmp(const node& a, const node& b){
    return a.a < b.a;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> cow[i].h >> cow[i].a >> cow[i].c;
    sort(cow + 1, cow + n + 1, cmp);
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= cow[i].c; j++)
            for (int k = cow[i].a; k >= cow[i].h; k--)
                dp[k] = max(dp[k], dp[k - cow[i].h] + cow[i].h);
    }
    int ans = 0;
    for (int i = 1; i <= cow[n].a; i++)
        ans = max(ans, dp[i]);
    cout << ans;
    return 0;
}